﻿@{
    ViewData["Title"] = "Home Page";
}

<div class="text-center">
    <h1 class="display-4">Welcome</h1>
    <div id="log">
     
    </div>
</div>
<script src="~/lib/stomp/stomp.js"></script>
<script>
          var i = 0;
          //声明个Stompjs客户端
    var client = Stomp.client("ws://42.51.42.120:15674/ws");
          //监听连接事件
          var on_connect = function (x) {
              id = client.subscribe("/topic/mq", function (d) {
                  if ((++i)%10==0)
                  {
                      $("#log").html(" ");
                      console.log("clear");
                  }
                  console.log(i);
                  $("#log").append('<p>' + d.body+'</p>');
              });
          };
          var on_error = function () {
              console.log('error');
          };
          //连接MQ
          client.connect('xman', 'xman01111', on_connect, on_error, '/');
</script>